package com.heraleign.boot.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.*;

public class UserService {
    @Autowired
    JdbcTemplate jdbcTemplate;

    public String getUser(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://172.18.0.57:3306/python_demo","python","python");
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery("select name,account from trade ");
            String result=null;
            while(rs.next()){
                //获取stuname这列数据
                String name = rs.getString("name");
                //获取stuid这列数据
                String account = rs.getString("account");

                result="name:"+name+",account:"+account;
            }

            rs.close();
            conn.close();
            return result;

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return "oj8k";
    }

    public String getUserFromDataSource(){

       // jdbcTemplate.queryForObject()

        return "";
    }
}
